package com.ucampus.dao;

import com.ucampus.dao.sql.BuildingSql;
import com.ucampus.entity.Building;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.UpdateProvider;

import java.util.List;

public interface BuildingDao {
    @Select("select id,name,introduction from building")
    List<Building> getAll();

    @Select("select id,name,introduction from building where name like CONCAT('%',#{name},'%')")
    List<Building> getByName(String name);

    @Insert("insert into building(name,introduction) values(#{name},#{introduction})")
    int add(String name, String introduction);

    @UpdateProvider(type = BuildingSql.class,method = "update")
    int update(int id,String name, String introduction);

    @Delete("<script>" +
            "delete from building where id in" +
            "<foreach collection='list' item='id' open='(' close=')' separator=','>#{id}</foreach>" +
            "</script>")
    int delete(List<Integer> list);

    @Select("select photo from building where id = #{id}")
    byte[] getImage(int id);
}
